package com.itheima.service.db.impl;

import com.itheima.domain.combat.Report;
import com.itheima.mapper.ReportMapper;
import com.itheima.service.db.ReportService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;
    //保存报告
    @Override
    public Integer saveReport(Report report) {
        reportMapper.insertReport(report);
        Integer reportId = report.getId();
        return reportId;
    }

    //根据报告的id和用户的id查询报告
    @Override
    public Report findReport(Integer reportId, Long loginUserId) {
        Report report = reportMapper.findByIdOrUid(reportId, loginUserId);
        return report;
    }

    //根据用户的ID查询报告
    @Override
    public List<Report> findByUserId(Long loginUserId) {
        List<Report> reportList = reportMapper.findByUserId(Integer.valueOf(loginUserId.toString()));
        return reportList;
    }

    //删除报告
    @Override
    public void deleteReport(Integer byUserIdReportId) {
        reportMapper.deleteReport(byUserIdReportId);
    }

    //根据用户的id和试卷的Id查询报告
    @Override
    public Report findByUserIdOrQuestionnaireId(Long loginUserId, Integer id) {
      Report report =  reportMapper.findByUserIdOrQuestionnaireId(loginUserId, id);
        return report;
    }
    //根据性格和问卷的ID查找性格
    @Override
    public  List<Report> findByConclusionOrQuestionnaireId(String conclusion, Integer questionnaireId) {
        List<Report> reportList = reportMapper.findByConclusionOrQuestionnaireId(conclusion, questionnaireId);
        return reportList;
    }


}
